package com.hff.pojo;

import java.io.Serializable;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @param <T>
 */
public class CallResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * 返回码
     * 0 正常，其他异常
     */
    private int returnCode = 0;
    
    /**
     * 描述
     */
    private String description = "OK";
    
    /**
     * 结果数据
     */
    private T result;
    
    public CallResult(){}
    
    public CallResult(int returnCode) {
        this.returnCode = returnCode;

    }

    public CallResult(T result) {
        this.result = result;
    }
    public CallResult(int returnCode, String description, T result) {
        this.returnCode = returnCode;
        this.description = description;
        this.result = result;
    }
    
    public int getReturnCode() {
        return returnCode;
    }
    public void setReturnCode(int returnCode) {
        this.returnCode = returnCode;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public T getResult() {
        return result;
    }
    public void setResult(T result) {
        this.result = result;
    }
    
    @Override
    public String toString() {
        //return JSON.toJSONString(this, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty);
        try {
            return new ObjectMapper().writeValueAsString(this);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "";
    }
}